package com.allen.ws;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.allen.feign.DemoFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestController
 * @Description TODO
 * @Autor ansonglin
 * @Date 2019/7/9 14:36
 * @Version 1.0
 **/
@RestController
@RequestMapping("/test")
public class DemoController {

    @Autowired
   private DemoFeign demoFeign;

    /**
     * feign调用测试
     * @return
     */
    @RequestMapping("/apiFeign")
    public String test(){
        return demoFeign.test();
    }


    /**
     * hystrix 熔断测试
     * @return
     */
    @RequestMapping("/hystrixTest")
    public String test1(){
        return meth();
    }

    @HystrixCommand(fallbackMethod = "defaultMeth")
    public String meth(){
//        demoFeign.test();

        int a = 0;
        int b = 11/a;
        return "api : hello world";
    }

    public String defaultMeth(){
        return "hystrix is working....";
    }
}
   